import { defineStore } from 'pinia'
import { i18n } from '@/i18n'

export const useAppStore = defineStore('app', {
  state() {
    return {
      inited: false, //初始化状态
      collapsed: false, //菜单折叠,
      isRouterAlive: true, //视图刷新
      isDarkTheme: false, //深浅色主题
      language: getLanguage() //语言
    }
  },
  getters: {
    getLanguage(state) {
      return Languages.filter((ele) => ele.id === state.language)[0]
    }
  },
  actions: {
    async Init() {
      this.inited = false
      await useUserStore().InitUserInfo()
      await useRoleStore().InitRoleInfo()
      await useMenuStore().InitMenuInfo()
      await useCodeStore().InitCodeInfo()
      useTagStore().InitTags()
      this.inited = true
    },
    SwitchCollapsed() {
      this.collapsed = !this.collapsed
    },
    ChangeLanguage(language: SupportLanguage) {
      this.language = language
      setLanguage(language)
      i18n.global.locale.value = language
    }
  }
})
